package lt.egidijus.aatest.model;

import java.util.ArrayList;

import lt.egidijus.aatest.utils.Constants;
import lt.egidijus.aatest.utils.Utils;

import org.eclipse.jdt.core.ICompilationUnit;

public class AAtestClass {
	
	private String name = "";
	private ICompilationUnit testingClass;
	private ICompilationUnit testRandom;
	private ICompilationUnit testGenetic;
	private ICompilationUnit testOCL;
	private ArrayList<ICompilationUnit> otherTestList = new ArrayList<ICompilationUnit>();
	
	public AAtestClass(ICompilationUnit cUnit) {
		this.add(cUnit);
	}
	
	public ICompilationUnit getTestingClass() {
		return testingClass;
	}
	public void setTestingClass(ICompilationUnit testingClass) {
		this.testingClass = testingClass;
		calculateName(testingClass);
	}
	public ICompilationUnit getTestRandom() {
		return testRandom;
	}
	public void setTestRandom(ICompilationUnit testRandom) {
		this.testRandom = testRandom;
		calculateName(testRandom);
	}
	public ICompilationUnit getTestGenetic() {
		return testGenetic;
	}
	public void setTestGenetic(ICompilationUnit testGenetic) {
		this.testGenetic = testGenetic;
		calculateName(testGenetic);
	}
	public ICompilationUnit getTestOCL() {
		return testOCL;
	}
	public void setTestOCL(ICompilationUnit testOCL) {
		this.testOCL = testOCL;
		calculateName(testOCL);
	}
	public ArrayList<ICompilationUnit> getOtherTestList() {
		return otherTestList;
	}
	public void setOtherTestList(ArrayList<ICompilationUnit> otherTestList) {
		this.otherTestList = otherTestList;
	}
	
	public void addOtherTestList(ICompilationUnit unit){
		this.otherTestList.add(unit);
	}
	
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	private void calculateName(ICompilationUnit cUnit){
		if (this.name.isEmpty()){
			this.name =  Utils.getClassName(cUnit);
		}
		
	}
	
	public void add(ICompilationUnit cUnit){
		String cName = cUnit.getElementName();
		if (cName.endsWith(Constants.testRandomClassPostfix+".java")){
			setTestRandom(cUnit);
		} else if (cName.endsWith(Constants.testOCLClassPostfix+".java")){
			setTestOCL(cUnit);
		} else if (cName.endsWith(Constants.testGeneticClassPostfix+".java")){
			setTestGenetic(cUnit);
		} else if (cName.lastIndexOf(Constants.testClassPostfix) > 0){
			otherTestList.add(cUnit);
			calculateName(cUnit);
			
		} else {
			setTestingClass(cUnit);
		}
	}

}
